package com.jxd.project.absence.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jxd.project.absence.dao.IUserDao;
import com.jxd.project.absence.model.User;
import com.jxd.project.absence.service.IUserService;
import com.jxd.project.absence.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author 李杨
 * @Date 2025/10/8 12:55
 * @Version 1.0
 */
@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserDao userDao;
    @Override
    public Map<String,Object> userLogin(Map<String,String> map) {
        String oldPwd = map.get("oldPwd");
        if (oldPwd != null) {
            map.put("pwd", oldPwd);
        }
        String  newPwd = map.get("newPwd");
        if (newPwd != null) {
            map.put("pwd", newPwd);
        }
        UserInfo userInfo = userDao.userLogin(map);
        if(userInfo != null) {
            String ename = userInfo.getEname();
            if (ename == null) {
                userInfo.setEname("管理员");
            }
        }
        Map<String,Object> res = new HashMap<>();
        if (userInfo == null){
            res.put("code", 499);
            res.put("msg", "用户名或密码错误");
        } else {
            res.put("code", 200);
            res.put("data", userInfo);
        }
        return res;
    }

    @Override
    public Boolean changePassword(Map<String, String> map) {
        return userDao.changePwd(map.get("userid"),map.get("pwd"));
    }
}
